package com.example.websocketdemo.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;

import java.io.IOException;

public class AccessDataService {

    public void a(String message) throws IOException {
        JSONObject transition = JSON.parseObject(message);
        String value = (String) transition.get("门禁数据区域名称");

        JSONObject jsonObject = new JSONObject();
        JSONObject xinxi = new JSONObject();
        JSONObject xinxi1 = new JSONObject();
        JSONObject xinxi2 = new JSONObject();
        JSONObject xinxi3 = new JSONObject();
        JSONObject xinxi4 = new JSONObject();

        JSONArray Array = new JSONArray();
        jsonObject.put("instruction","menjin");
        if (value.equals("消防泵房")){
            xinxi.put("姓名","001");
            xinxi.put("身份证号","139219200103016789");
            xinxi.put("有效期起","-");
            xinxi.put("有效期止","-");
            xinxi.put("区域","消防泵房");
            xinxi.put("单位","-");
            xinxi.put("工种","-");
            xinxi.put("issue","false");

            xinxi4.put("姓名","004");
            xinxi4.put("身份证号","139219198103016789");
            xinxi4.put("有效期起","-");
            xinxi4.put("有效期止","-");
            xinxi4.put("区域","消防泵房");
            xinxi4.put("单位","-");
            xinxi4.put("工种","-");
            xinxi4.put("issue","false");

            Array.add(xinxi);
            Array.add(xinxi4);
        }else if (value.equals("泡沫站")){
            xinxi1.put("姓名","001");
            xinxi1.put("身份证号","139219198109016789");
            xinxi1.put("有效期起","-");
            xinxi1.put("有效期止","-");
            xinxi1.put("区域","消防泵房");
            xinxi1.put("单位","-");
            xinxi1.put("工种","-");
            xinxi1.put("issue","true");
            Array.add(xinxi1);
        }else if (value.equals("应急水池站")){
            xinxi2.put("姓名","002");
            xinxi2.put("身份证号","139219198903016789");
            xinxi2.put("有效期起","-");
            xinxi2.put("有效期止","-");
            xinxi2.put("区域","消防泵房");
            xinxi2.put("单位","-");
            xinxi2.put("工种","-");
            xinxi2.put("issue","false");
            Array.add(xinxi2);
        }else if (value.equals("HDPE装置")){
            xinxi3.put("姓名","003");
            xinxi3.put("身份证号","139219199103016789");
            xinxi3.put("有效期起","-");
            xinxi3.put("有效期止","-");
            xinxi3.put("区域","消防泵房");
            xinxi3.put("单位","-");
            xinxi3.put("工种","-");
            xinxi2.put("issue","false");
            Array.add(xinxi3);
        }
        jsonObject.put("array",Array);
        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
    }
}
